package bootstrap

import (
	g "com.codingq92/go-chat/global"
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"go.uber.org/zap"
)

// InitRedis 初始化Redis
func InitRedis() {
	addr := fmt.Sprintf("%s:%d", g.Config.Redis.Host, g.Config.Redis.Port)
	client := redis.NewClient(&redis.Options{
		Addr:     addr,
		Password: g.Config.Redis.Password, // no password set
		DB:       g.Config.Redis.DB,       // use default DB
	})
	_, err := client.Ping(context.Background()).Result()
	if err != nil {
		g.Log.Error("Redis connect ping failed, err:", zap.Any("err", err))
		return
	}
	g.Redis = client
	g.Log.Info(">>>>>>>>>>>>>> Redis[" + addr + "] connect success >>>>>>>>>>>>>>>")
}
